<?php

namespace html;

use Classes\autoload\SplClassLoader;
use Classes\User;
use PDO;
use Classes;
use Classes\Relation;
use Classes\Event;

class SearchResults {
	public static function showUsers($username) {
		$users = Classes\User::searchUser ( $username );
		
		if (isset ( $_SESSION ['userPrincipal'] )) {
			$userPrincipal = $_SESSION ['userPrincipal'];
		}
		
		echo '<p>Резултати от търсенето:</p>';
		foreach ( $users as $user ) {
			if ($user ['user_id'] != $userPrincipal->getUserId ()) {
				echo '<p><a href="?profile=' . $user ['user_id'] . '">' . $user ['user_name'] . '</a></p>';
				if (Relation::isRelation ( $userPrincipal->getUserId (), $user ['user_id'] ) == 1) {
					echo '<a href="?relation=end&user=' . $user ['user_id'] . '">Спри да следваш</a>';
				}
				if (Relation::isRelation ( $userPrincipal->getUserId (), $user ['user_id'] ) == 0) {
					echo '<a href="?relation=start&user=' . $user['user_id'] . '">Следвай</a>';
				}
			}
		}
	}
	
	public static function showEvents ($event_name) {
		$events = Classes\Event::searchEvent($event_name);
		
		if (isset ( $_SESSION ['userPrincipal'] )) {
			$userPrincipal = $_SESSION ['userPrincipal'];
		}
		
		echo '<p>Резултати от търсенето:</p>';
		
		foreach ($events as $event) {
			if ($userPrincipal->getRank() == 10) {
				echo '<div>';
				echo '<p><a href="?event=' . $event ['event_id'] . '">' . $event ['event_name'] . '</a></p>';
				echo '<p><a href="?del-event=' . $event ['event_id'] . '">Изтрий</a></p>';
				echo '</div>';
			} else {
				
				$ev = Classes\Event::getEvent($event['event_id']);
				$ev = $ev[0];
				
				echo '<div>';
				echo '<p><a href="?event=' . $event ['event_id'] . '">' . $event ['event_name'] . '</a></p>';
				
				if ($userPrincipal->getUserId() == $ev['author_id']) {
					echo '<p><a href="?del-event=' . $event ['event_id'] . '">Изтрий</a></p>';
				}
				
				
				
				
				echo '</div>';
				
				
				
			}
		}
	}
	
	public static function showMyEvents ($user_id) {
		$events = Classes\Event::getEventsByUserId($user_id);
		
		if (isset ( $_SESSION ['userPrincipal'] )) {
			$userPrincipal = $_SESSION ['userPrincipal'];
		}
		
		echo '<p>Резултати от търсенето:</p>';
		
		foreach ($events as $event) {
			echo '<div>';
			echo '<p><a href="?event=' . $event ['event_id'] . '">' . $event ['event_name'] . '</a></p>';
			echo '<p><a href="?del-event=' . $event ['event_id'] . '">Изтрий</a></p>';
			echo '</div>';
		}
	}
	
}